# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libcaca

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.99.beta18
pkgrel=1
pkgdesc="Color AsCii Art library (mingw-w64)"
arch=('any')
url="http://caca.zoy.org/wiki/libcaca"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
    "${MINGW_PACKAGE_PREFIX}-pkg-config"
    #"${MINGW_PACKAGE_PREFIX}-ncurses"
    "${MINGW_PACKAGE_PREFIX}-python2"
    )
depends=("${MINGW_PACKAGE_PREFIX}-zlib" "${MINGW_PACKAGE_PREFIX}-freetype" "${MINGW_PACKAGE_PREFIX}-fontconfig" "${MINGW_PACKAGE_PREFIX}-cppunit")
options=(!libtool strip staticlibs)
source=(http://libcaca.zoy.org/files/libcaca/${_realname}-${pkgver}.tar.gz
    0001-win32-is-not-msvc-it-could-be.mingw.patch
    0002-correct-installation-order.mingw.patch
    0003-correct-builddir-reference.mingw.patch)
md5sums=('93d35dbdb0527d4c94df3e9a02e865cc'
         'b1b859f5af37400e439db211685e1cc7'
         '1c68758085bd3056d78ebc9bbe804b84'
         'f919daa538638d9198e91cf87efec406')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-win32-is-not-msvc-it-could-be.mingw.patch
  patch -p1 -i ${srcdir}/0002-correct-installation-order.mingw.patch
  patch -p1 -i ${srcdir}/0003-correct-builddir-reference.mingw.patch
  
  autoreconf -fi
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --disable-static \
    --enable-shared \
    --disable-ncurses
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="$pkgdir" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
